/*
 * PaymentHandler.java
 *
 * Created on April 3, 2007, 2:46 AM
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package edu.byu.isys413.group1E.handlers;

import edu.byu.isys413.group1E.data.PaymentBO;
import edu.byu.isys413.group1E.data.PaymentDAO;

/**Handles all business logic concerning Payments
 *
 * @author tkulbeth
 */
public class PaymentHandler {
    /**
     * Contains an instance of PaymentHandler
     */
    private static PaymentHandler instance = null;
    
    /**
     * Creates a new instance of PaymentHandler
     */
    public PaymentHandler() {
    }
    
    /**
     * Retrieves an instance of the PaymentHandler object
     * 
     * @return instance of PaymentHandler
     */
    public static synchronized PaymentHandler getInstance() {
        if (instance == null) {
            instance = new PaymentHandler();
        }
        return instance;
    }

    /**
     * Processes a payment made by a customer, returns a PaymentBO.
     *@param amt contains the amount paid
     *@param method contains the method of payment
     *@return a PaymentBO.
     */
    public synchronized PaymentBO makePayment(String amt, String method, String change) throws Exception{
        PaymentBO pmt = PaymentDAO.getInstance().create();
        pmt.setPmtAmount(Double.parseDouble(amt));
        pmt.setType(method);
        pmt.setPmtChange(Double.parseDouble(change));
        return pmt;
    }
}
